////////////////////////////////////////////////////////////////////////////////////////////////////
/// Copyright (c) 2009 - 2010 RacoonStudios
///
/// Permission is hereby granted, free of charge, to any person obtaining a copy of this
/// software and associated documentation files (the "Software"), to deal in the Software
/// without restriction, including without limitation the rights to use, copy, modify, merge,
/// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
/// to whom the Software is furnished to do so, subject to the following conditions:
///
/// The above copyright notice and this permission notice shall be included in all copies or
/// substantial portions of the Software.
///
/// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
/// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
/// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
/// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
/// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
/// DEALINGS IN THE SOFTWARE.
////////////////////////////////////////////////////////////////////////////////////////////////////

#pragma once
#ifndef float2_h__
#define float2_h__

#include "math/scalar.h"

namespace Math
{
	////////////////////////////////////////////////////////////////////////////////////////////////////
	/// \class	float2
	///
	/// \brief	This float2 is an easy and simple representation of objects within the
	///			2d world.
	///			This will be necessary of a GUI or HUD or even when you want to make a 
	///			2d game with this engine which should also be possible.
	///			But if you want to use deep you should is the float4 and use the z coordinate
	///			as z-index. 
	///
	/// \author	khaos
	/// \date	05.12.2009
	////////////////////////////////////////////////////////////////////////////////////////////////////
	class float2
	{
		public:

			friend class point2;

			////////////////////////////////////////////////////////////////////////////////////////////////////
			/// \fn	float2()
			///
			/// \brief	Default constructor. 
			///
			/// \author	khaos
			/// \date	05.12.2009
			////////////////////////////////////////////////////////////////////////////////////////////////////
			float2();

			////////////////////////////////////////////////////////////////////////////////////////////////////
			/// \fn	float2(scalar x, scalar y)
			///
			/// \brief	Constructor. 
			///
			/// \author	khaos
			/// \date	05.12.2009
			///
			/// \param	[in]	x	The x coordinate. 
			/// \param	[in]	y	The y coordinate. 
			////////////////////////////////////////////////////////////////////////////////////////////////////
			float2(scalar x, scalar y);

			////////////////////////////////////////////////////////////////////////////////////////////////////
			/// \fn	float2(const float2 & rhs)
			///
			/// \brief	Constructor. 
			///
			/// \author	khaos
			/// \date	05.12.2009
			///
			/// \param	[in]	rhs	The right hand side object. 
			////////////////////////////////////////////////////////////////////////////////////////////////////
			float2(const float2 & rhs);




			////////////////////////////////////////////////////////////////////////////////////////////////////
			/// \fn	void operator= (const float2 & rhs)
			///
			/// \brief	Copy operator. 
			///
			/// \author	khaos
			/// \date	05.12.2009
			///
			/// \param	[in]	rhs	The right hand side object. 
			////////////////////////////////////////////////////////////////////////////////////////////////////
			void operator = (const float2 & rhs);

			////////////////////////////////////////////////////////////////////////////////////////////////////
			/// \fn	bool operator== (const float2 & rhs) const
			///
			/// \brief	Equality operator. 
			///
			/// \author	khaos
			/// \date	05.12.2009
			///
			/// \param	[in]	rhs	The right hand side object. 
			///
			/// \return	True if both are the same, otherwise false.
			////////////////////////////////////////////////////////////////////////////////////////////////////
			bool operator == (const float2 & rhs) const;

			////////////////////////////////////////////////////////////////////////////////////////////////////
			/// \fn	bool operator!= (const float2 & rhs) const
			///
			/// \brief	Inequality operator. 
			///
			/// \author	khaos
			/// \date	05.12.2009
			///
			/// \param	[in]	rhs	The right hand side object. 
			///
			/// \return	True if both are inequal, otherwise false.
			////////////////////////////////////////////////////////////////////////////////////////////////////
			bool operator != (const float2 & rhs) const;

			////////////////////////////////////////////////////////////////////////////////////////////////////
			/// \fn	void operator+= (const float2 & rhs)
			///
			/// \brief	Assignment by addition operator. 
			///
			/// \author	khaos
			/// \date	05.12.2009
			///
			/// \param	[in]	rhs	The right hand side object. 
			////////////////////////////////////////////////////////////////////////////////////////////////////
			void operator += (const float2 & rhs);

			////////////////////////////////////////////////////////////////////////////////////////////////////
			/// \fn	void operator-= (const float2 & rhs)
			///
			/// \brief	Assignment by subtraction operator. 
			///
			/// \author	khaos
			/// \date	05.12.2009
			///
			/// \param	[in]	rhs	The right hand side object. 
			////////////////////////////////////////////////////////////////////////////////////////////////////
			void operator -= (const float2 & rhs);

			////////////////////////////////////////////////////////////////////////////////////////////////////
			/// \fn	void operator*= (scalar s)
			///
			/// \brief	Assignment by multiplication operator. 
			///
			/// \author	khaos
			/// \date	05.12.2009
			///
			/// \param	[in]	s	The multiplication factor. 
			////////////////////////////////////////////////////////////////////////////////////////////////////
			void operator *= (scalar s);

			////////////////////////////////////////////////////////////////////////////////////////////////////
			/// \fn	float2 operator- () const
			///
			/// \brief	Invertation operator. 
			///
			/// \author	khaos
			/// \date	05.12.2009
			///
			/// \return	The inverted float2.
			////////////////////////////////////////////////////////////////////////////////////////////////////
			float2 operator - () const;

			////////////////////////////////////////////////////////////////////////////////////////////////////
			/// \fn	float2 operator+ (const float2 & rhs) const
			///
			/// \brief	Addition operator. 
			///
			/// \author	khaos
			/// \date	05.12.2009
			///
			/// \param	[in]	rhs	The right hand side object. 
			///
			/// \return	A float2 containing the addition of both float2. 
			////////////////////////////////////////////////////////////////////////////////////////////////////
			float2 operator + (const float2 & rhs) const;

			////////////////////////////////////////////////////////////////////////////////////////////////////
			/// \fn	float2 operator- (const float2 & rhs) const
			///
			/// \brief	Negation operator. 
			///
			/// \author	khaos
			/// \date	05.12.2009
			///
			/// \param	[in]	rhs	The right hand side object. 
			///
			/// \return	A float2 containing the subtraction of both float2.
			////////////////////////////////////////////////////////////////////////////////////////////////////
			float2 operator - (const float2 & rhs) const;

			////////////////////////////////////////////////////////////////////////////////////////////////////
			/// \fn	float2 operator* (scalar s) const
			///
			/// \brief	Multiplication operator. 
			///
			/// \author	khaos
			/// \date	05.12.2009
			///
			/// \param	[in]	s	The multiplication factor.. 
			///
			/// \return	A float2 containing the multiplicatio of this float2 and a scalar. 
			/////////////////////////////////////////////////////////////////////////////////////////////////////
			float2 operator * (scalar s) const;




			////////////////////////////////////////////////////////////////////////////////////////////////////
			/// \fn	void set(scalar x, scalar y)
			///
			/// \brief	Sets the x and y coordinates.
			///
			/// \author	khaos
			/// \date	05.12.2009
			///
			/// \param	[in]	x	The x coordinate. 
			/// \param	[in]	y	The y coordinate. 
			////////////////////////////////////////////////////////////////////////////////////////////////////
			void set(scalar x, scalar y);

			////////////////////////////////////////////////////////////////////////////////////////////////////
			/// \fn	void setx(scalar x)
			///
			/// \brief	Sets the x coordinate.
			///
			/// \author	khaos
			/// \date	05.12.2009
			///
			/// \param	[in]	x	The x coordinate. 
			////////////////////////////////////////////////////////////////////////////////////////////////////
			void setx(scalar x);

			////////////////////////////////////////////////////////////////////////////////////////////////////
			/// \fn	void sety(scalar y)
			///
			/// \brief	Sets the y coordinate.
			///
			/// \author	khaos
			/// \date	05.12.2009
			///
			/// \param	[in]	y	The y coordinate. 
			////////////////////////////////////////////////////////////////////////////////////////////////////
			void sety(scalar y);

			////////////////////////////////////////////////////////////////////////////////////////////////////
			/// \fn	scalar & getx()
			///
			/// \brief	Returns the x coord with read and write access.
			///
			/// \author	khaos
			/// \date	05.12.2009
			///
			/// \return	The x coordinate.
			////////////////////////////////////////////////////////////////////////////////////////////////////
			scalar & getx();

			////////////////////////////////////////////////////////////////////////////////////////////////////
			/// \fn	scalar & gety()
			///
			/// \brief	Returns the y coord with read and write access.
			///
			/// \author	khaos
			/// \date	05.12.2009
			///
			/// \return	The y coordinate.
			////////////////////////////////////////////////////////////////////////////////////////////////////
			scalar & gety();

			////////////////////////////////////////////////////////////////////////////////////////////////////
			/// \fn	scalar getx() const
			///
			/// \brief	Returns the x coord only with reading access.
			///
			/// \author	khaos
			/// \date	05.12.2009
			///
			/// \return	The x coordinate.
			////////////////////////////////////////////////////////////////////////////////////////////////////
			scalar getx() const;

			////////////////////////////////////////////////////////////////////////////////////////////////////
			/// \fn	scalar gety() const
			///
			/// \brief	Returns the y coord only with reading access.
			///
			/// \author	khaos
			/// \date	05.12.2009
			///
			/// \return	The y coordinate.
			////////////////////////////////////////////////////////////////////////////////////////////////////
			scalar gety() const;




			////////////////////////////////////////////////////////////////////////////////////////////////////
			/// \fn	scalar length() const
			///
			/// \brief	Returns the length of the float2.
			///
			/// \author	khaos
			/// \date	05.12.2009
			///
			/// \return	The length of the float2..
			////////////////////////////////////////////////////////////////////////////////////////////////////
			scalar length() const;

			////////////////////////////////////////////////////////////////////////////////////////////////////
			/// \fn	scalar lengthsq() const
			///
			/// \brief	Returns the squared length.
			///			In some situations it's better to return the squared length and later take 
			///			the square root because this is an expensive operation, so we want as less
			///			as possible of it.
			///
			/// \author	khaos
			/// \date	05.12.2009
			///
			/// \return	The squared length of the float2..
			////////////////////////////////////////////////////////////////////////////////////////////////////
			scalar lengthsq() const;

			////////////////////////////////////////////////////////////////////////////////////////////////////
			/// \fn	float2 abs() const
			///
			/// \brief	Returns the absolute of the float2.
			///
			/// \author	khaos
			/// \date	05.12.2009
			///
			/// \return	The absolute of the float2.
			////////////////////////////////////////////////////////////////////////////////////////////////////
			float2 abs() const;




			////////////////////////////////////////////////////////////////////////////////////////////////////
			/// \fn	static float2 maximize(const float2 & f1, const float2 & f2)
			///
			/// \brief	Returns the maximum of the two specified float2's.
			///
			/// \author	khaos
			/// \date	05.12.2009
			///
			/// \param	[in]	f1	The first float2. 
			/// \param	[in]	f2	The second float2. 
			///
			/// \return	The maximized version of the two specified float2's.
			////////////////////////////////////////////////////////////////////////////////////////////////////
			static float2 maximize(const float2 & f1, const float2 & f2);

			////////////////////////////////////////////////////////////////////////////////////////////////////
			/// \fn	static float2 minimize(const float2 & f1, const float2 & f2)
			///
			/// \brief	Returns the minimum of the two specified float2's.
			///
			/// \author	khaos
			/// \date	05.12.2009
			///
			/// \param	[in]	f1	The first float2. 
			/// \param	[in]	f2	The second  float2. 
			///
			/// \return	The minimized version of the two specified float2's.
			////////////////////////////////////////////////////////////////////////////////////////////////////
			static float2 minimize(const float2 & f1, const float2 & f2);

			////////////////////////////////////////////////////////////////////////////////////////////////////
			/// \fn	static float2 normalize(const float2 & f)
			///
			/// \brief	Returns a normalized version of the specified float2.
			///
			/// \author	khaos
			/// \date	05.12.2009
			///
			/// \param	[in]	f	The float2 we want the normal off.
			///
			/// \return	The normalized version of the specified float2.
			////////////////////////////////////////////////////////////////////////////////////////////////////
			static float2 normalize(const float2 & f);

			////////////////////////////////////////////////////////////////////////////////////////////////////
			/// \fn	static float2 lerp(const float2 & f1, const float2 & f2, scalar s)
			///
			/// \brief	Returns a point of the interpolation of the two float2's and
			///			the specified factor s.
			///
			/// \author	khaos
			/// \date	05.12.2009
			///
			/// \param	[in]	f1	The first float2. 
			/// \param	[in]	f2	The second float2. 
			/// \param	[in]	s	The interpolation factor.
			///
			/// \return	The interpolated float2.
			////////////////////////////////////////////////////////////////////////////////////////////////////
			static float2 lerp(const float2 & f1, const float2 & f2, scalar s);

			////////////////////////////////////////////////////////////////////////////////////////////////////
			/// \fn	static float2 less(const float2 & f1, const float2 & f2)
			///
			/// \brief	Less. 
			///
			/// \author	khaos
			/// \date	05.12.2009
			///
			/// \param	[in]	f1	The first float2. 
			/// \param	[in]	f2	The second float2. 
			///
			/// \return	If true a minimized float2, otherwise a maximized.
			////////////////////////////////////////////////////////////////////////////////////////////////////
			static float2 less(const float2 & f1, const float2 & f2);

			////////////////////////////////////////////////////////////////////////////////////////////////////
			/// \fn	static float2 lessequal(const float2 & f1, const float2 & f2)
			///
			/// \brief	Lessequals. 
			///
			/// \author	khaos
			/// \date	05.12.2009
			///
			/// \param	[in]	f1	The first const float2 &. 
			/// \param	[in]	f2	The second const float2 &. 
			///
			/// \return	If true a minimized float2, otherwise a maximized.
			////////////////////////////////////////////////////////////////////////////////////////////////////
			static float2 lessequal(const float2 & f1, const float2 & f2);

			////////////////////////////////////////////////////////////////////////////////////////////////////
			/// \fn	static float2 greater(const float2 & f1, const float2 & f2)
			///
			/// \brief	Greaters. 
			///
			/// \author	khaos
			/// \date	05.12.2009
			///
			/// \param	[in]	f1	The first float2. 
			/// \param	[in]	f2	The second float2. 
			///
			/// \return	If true a maximized float2, otherwise a minimized. 
			////////////////////////////////////////////////////////////////////////////////////////////////////
			static float2 greater(const float2 & f1, const float2 & f2);

			////////////////////////////////////////////////////////////////////////////////////////////////////
			/// \fn	static float2 greaterequal(const float2 & f1, const float2 & f2)
			///
			/// \brief	Greaterequals. 
			///
			/// \author	khaos
			/// \date	05.12.2009
			///
			/// \param	[in]	f1	The first float2. 
			/// \param	[in]	f2	The second float2. 
			///
			/// \return	If true a maximized float2, otherwise a minimized. 
			////////////////////////////////////////////////////////////////////////////////////////////////////
			static float2 greaterequal(const float2 & f1, const float2 & f2);

		protected:

			scalar m_x;
			scalar m_y;
			
		private:

	};

}

#endif // float2_h__